<?php
	$obj=new ObjRequest();
	$us=new User();
	if ( strcasecmp( @ $_SERVER['REQUEST_METHOD'], 'POST' ) == 0 )
	{
		//print_r($_POST['delete']);
		$arr=$_POST['delete'];
		$s=arrToList($arr,",");
		if(count($arr)>0)
			foreach($arr as $key => $val)
			{
				$obj->RequestID=$val;
				$obj->delete($conn);
			}
		$arruser=$_POST['user'];
		$arrresolvedate=$_POST['ResolveDate'];
		$arrstatus=$_POST['Status'];
		print_r($arrstatus);
		if(count($arruser)>0)
			foreach($arruser as $key => $val)
			{
				$obj->RequestID=$key;
				$obj->ResolveBy= $val;
				$obj->ResolveDate= $dt-> _formatDateDMYtoYMD( $arrresolvedate[$key]);
				if($val!="")
					$obj->updateResolve($conn);
				$obj->Status=$arrstatus[$key];
				$obj->updateStatus($conn);
				
			}
		linkto("?module=$module");	
	}
	
?>
<form name="f" action="" method="post" enctype="multipart/form-data">
<div class="ContentTitle">
    <div class="left" style="padding-top:8px"><?php echo $objModule->ModuleName?></div>
    <div class="CMSButton right">
        <?php
		if($objUserType->isAllow($objModule->ModuleID,1)!=-1)
		{
		?>
		<a href="?module=<?php echo $module?>&action=add">Submit new request</a>
		<?php
		}
		?>
        <a href="#" onclick="f.submit()">Update resolve</a>
    </div>    
    <div class="clear"></div>
</div>
<ul id="ContentTabs" class="shadetabs">
    <!--
    <li><a class="selected" onclick="ShowHideDiv('Tab',1,2)">General Information</a></li>
    <li><a onclick="ShowHideDiv('Tab',1,2)">Account Information</a></li>
    -->
</ul>       

<div id="Tab1" class="TabContainer" style="display:block">
<!-------------CONTENT OF EACH MODULE ---------------------------->
<table width="100%" class="list">
	<thead>
   	  <tr class="thead">
      	  <td class="tdright" width="33">
          <input type="checkbox" onclick="$('input[name*=\'delete\']').attr('checked', this.checked);"/>
          </td>
          <td class="tdleft">RequestID</td>
          <td class="tdleft">Tiêu đề</td>
          <td class="tdleft">Response By</td>
          <td class="tdleft">Response Date</td>
          <td class="tdleft">Resolve By</td>
          <td class="tdleft">Resolve Date</td>
          <td class="tdleft">Status</td>
          <td class="tdleft">Post</td>
      </tr>
    </thead>
    <tbody>
<?php
	
	$data=array();
	$data=$obj->travel(" WHERE Status <> 3 ORDER BY RequestID");
	for($i=0;$i<count($data);$i++)
	{
		$obj->loadByKey($data[$i]);
		
		$status=$obj->getStatus();
		
?>
    	<tr bgcolor="<?php echo $status['Color']?>">
            <td class="tdright">
            <input type="checkbox" name="delete[<?php echo $i?>]" value="<?php echo $obj->RequestID?>"/>
            </td>
            <td class="tdleft" ><a href="?module=<?php echo $module?>&action=detail&id=<?php echo $obj->RequestID?>"><?php echo $obj->RequestID?></a></td>
            <td class="tdleft"><?php echo $obj->Title?></td>
            <td class="tdleft"><?php echo $obj->ResponseBy?></td>
            <td class="tdleft"><?php echo dateFormat($obj->ResponseDate)?></td>
            <td class="tdleft"><?php
			if($objUser->UserTypeID=="admin")
            	echo $us->cbUser("user[".$obj->RequestID."]", $obj->ResolveBy ,"");
			else
			{
				$us->loadByKey($obj->ResolveBy);
				echo $us->UserName;
			}
			?></td>
            <td class="tdleft">
            <?php
            if($objUser->UserTypeID=="admin")
			{
			?>
            	<input type='text' name='ResolveDate[<?php echo $obj->RequestID?>]' value="<?php 
					if(dateFormat($obj->ResolveDate)=="00/00/0000") 
						echo $dt->_getDateNowDMY("/") ;
					else 
						echo dateFormat($obj->ResolveDate); ?>" style="width:80px"/>
							<a href="javascript:cal<?php echo $i?>.popup();"><img src='images/cal.gif' width='16' height='16' border='0' alt='Ngay Thang'></a>
	<script language='JavaScript'>
		var cal<?php echo $i?> = new calendar2(document.forms['f'].elements['ResolveDate[<?php echo $obj->RequestID?>]']);
		//var cal4 = new calendar1(document.forms['frmSubmit'].elements('txtDate'));
		cal<?php echo $i?>.year_scroll = true;
		cal<?php echo $i?>.time_comp = true;
</script>
            <?php
			}
			else
				if(dateFormat($obj->ResolveDate)=="00/00/0000") 
					echo $dt->_getDateNowDMY("/") ;
				else 
					echo dateFormat($obj->ResolveDate); 
			?>
            	
			</td>
	
            <td class="tdleft"><?php
			
            if($objUser->UserTypeID=="admin")
            	echo $obj->cbStatus("Status[".$obj->RequestID."]",$obj->Status,"");
			else
			{
				$arr = $obj->getStatus();
				echo $arr["Name"];
			}
			?></td>
          	<td class="tdleft"><?php echo count($obj->getPost())?></td>
        </tr>
<?php
	}
?>
    </tbody>
</table>

<!-------------END CONTENT OF EACH MODULE ---------------------------->
</div>
</form>
<script language="javascript">
from=document.f
function fsubmit()
{
	anser=confirm('Are you sure delete !')
	if(anser==true)
	{
		from.submit()
	}
}
</script>
